package logc.repository.session;

import java.io.*;

import logc.model.Comment;

import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.*;

public class CommentSessionRepository {
	private final static String namespace = "mybatis.mapper.CommentMapper";

	private static SqlSessionFactory getSqlSessionFactory() {
		String resource = "mybatis-config.xml";
		InputStream inputStream;
		try {
			inputStream = Resources.getResourceAsStream(resource);
		} catch (IOException e) {
			throw new IllegalArgumentException(e);
		}
		return new SqlSessionFactoryBuilder().build(inputStream);
	}


	
	public static Integer insertLogmast(Comment comment) {
		SqlSession sqlSession = getSqlSessionFactory().openSession();
		try {
			String statement = namespace + ".insertLogmast";
			int result = sqlSession.insert(statement, comment);
			if (result > 0) {
				sqlSession.commit();
				System.out.println("성공");
			} else {
				sqlSession.rollback();
				System.out.println("실패");
			}
			return result;
		} finally {
			sqlSession.close();
		}
	}
}
